package com.baking.service.impl;

import com.baking.dao.OrderMapper;
import com.baking.model.Collect;
import com.baking.model.Order;
import com.baking.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @Author:wrb
 * @Date :2020/1/13/22:58
 * @Describtion:
 **/
@Service("OrderService")
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public List<Order> getOrderList(Order order) {
        List<Order> orderList = null;
        try {
            orderList = orderMapper.getOrderList(order);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return orderList;
    }

    @Override
    public boolean addOrder(Order order) {
        order.setInsertDate(new Timestamp(System.currentTimeMillis()));
        //生成订单号：年月日时分秒
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        order.setBookingId(sdf.format(new Date()));
        boolean b = false;
        try {
            b =  orderMapper.addOrder(order);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return b;
    }

    @Override
    public boolean deleteOrder(Order order) {
        boolean b = false;
        try {
            b =  orderMapper.deleteOrder(order);;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return b;
    }

    @Override
    public boolean updateOrder(Order order) {
        order.setUpdateDate(new Timestamp(System.currentTimeMillis()));
        boolean b = false;
        try {
            b =  orderMapper.updateOrder(order);;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return b;
    }

    @Override
    public boolean addCollect(Collect collect) {
        collect.setUpdateDate(new Timestamp(System.currentTimeMillis()));
        boolean b = false;
        try {
            b =  orderMapper.addCollect(collect);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return b;
    }

    @Override
    public boolean deleteCollect(Collect collect) {
        boolean b = false;
        try {
            b =  orderMapper.deleteCollect(collect);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return b;
    }
}
